package com.hnust.utils;

import com.cleveroom.core.CRMDevice;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/4/21
 * 描述：
 */
public class SimpleTools {
    /**
     * D5	D6	D7
     * 数据（低位）	数据2	数据3（高位）
     * @return 计算结果
     */
    public static long convertToData(int D5, int D6, int D7){
        String sD5=Integer.toBinaryString(D5);
        String sD6=Integer.toBinaryString(D6);
        StringBuilder sDb=new StringBuilder(Integer.toBinaryString(D7));
        for(int i=1;i<=8-sD6.length();i++){
            sDb.append("0");
        }
        sDb.append(sD6);
        for(int i=1;i<=8-sD5.length();i++){
            sDb.append("0");
        }
        sDb.append(sD5);
        return Integer.parseUnsignedInt(sDb.toString(),2);
    }

    /**
     * crmDevice中的命令转化为逗号隔开的字符串形式(D1..,D7)
     * @param crmDevice 参数
     * @return 计算结果
     */
    public static String crmDeviceToString(CRMDevice crmDevice){
        return ","+crmDevice.getD1()+
                ","+crmDevice.getD2()+
                "," +crmDevice.getD3() +
                "," +crmDevice.getD4() +
                "," +crmDevice.getD5() +
                "," +crmDevice.getD6() +
                ","+crmDevice.getD7();
    }
}
